package com.sgb.goods.viewmodel;

import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.sgb.goods.api.GoodsCallBack;
import com.sgb.goods.api.GoodsNet;
import com.sgb.goods.entity.ShopMyPriceListEntity;
import com.sgb.goods.utils.Constants;
import com.sgb.goods.utils.base.viewmodel.BaseViewModel;
import com.sgb.goods.utils.module.GoodsModule;
import com.sgb.goods.view.adapter.ShopMyPriceAdapter;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.H5ReEntity;
import com.swgk.core.base.model.entity.ListResponse;

import java.util.List;

/**
 * 我的报价
 * @author cyj
 */
public class ShopMyPriceModel extends BaseViewModel {

    private int page = 1;
    public ShopMyPriceAdapter adapter;
    public MutableLiveData<List<ShopMyPriceListEntity>> dataList = new MutableLiveData<>();

    public ShopMyPriceModel() {
        adapter = new ShopMyPriceAdapter();
    }

    /** 查询我的报价列表 */
    public void getDataList(int status, String search, boolean isLoadMore) {
        page = isLoadMore ? page + 1 : Constants.PAGE_NUM;
        showLoading();
        GoodsNet.getInstance().getGoodsApi().getPriceShop(status, page, Constants.PAGE_SIZE_10, search)
                .enqueue(new GoodsCallBack<BaseEntity<ListResponse<List<ShopMyPriceListEntity>>>>() {

            @Override
            public void onSuccess(BaseEntity<ListResponse<List<ShopMyPriceListEntity>>> data) {
                if(isLoadMore) {
                    adapter.addData(data.getData().getList());
                } else {
                    adapter.setNewData(data.getData().getList());
                }
                dataList.setValue(data.getData().getList());
            }

            @Override
            public void onFail() {
                dataList.setValue(null);
            }
        });
    }

    /** 查询详情数据 */
    public void getDataInfo(String note) {
        showLoading();
        GoodsNet.getInstance().getGoodsApi().getUrlSetting("pensonalQuoteDetail")
                .enqueue(new GoodsCallBack<BaseEntity<H5ReEntity>>() {

            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                String url = data.getData().getUrl() + "?no=" + note;
                GoodsModule.getInstance().call1("jumpMyOfferDetails", url);
            }
        });
    }
}
